package game.io;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Vector;
import game.classes.GameMode;

/**
 * @author Chris
 */
public class Keyboard implements KeyListener {

    private Vector keystowarn;
    private GameMode mode;

    public Keyboard(GameMode mode) {
        this.keystowarn = new Vector();
        this.mode = mode;
    }

    public void addKey(int k) {
        keystowarn.add(k);
    }

    public void removeKey(int k) {
        keystowarn.remove(k);
    }

    private boolean alertThis(KeyEvent e) {
        return this.keystowarn.contains(e.getKeyCode());
    }

    public void keyTyped(KeyEvent e) {
    }

    public void keyPressed(KeyEvent e) {
        if (this.alertThis(e)) {
            this.mode.notifyKeypress(e);
        }
    }

    public void keyReleased(KeyEvent e) {
        if (this.alertThis(e)) {
            this.mode.notifyKeyrelease(e);
        }
    }
}
